/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-11-12
 * @Time  : 下午3:09
 * @brief :
 */
exports.uservoice = function(){
    var $widget = $(".index-widget-uservoice"),
        $widgetContainer = $widget.find('.widget-container'),
        $widgetPage = $widgetContainer.find('.widget-page'),
        $points = $widget.find('.points'),
        count = $widgetPage.length,
        interval = 0,
        cur = 0;

//    for(var i=0;i<count;i++){
//        $points.append('<i '+(i==0?'class="active"':'')+'></i>')
//    }

    function slider(index){
        $widgetPage.removeClass('active').css('z-index',0);
        $widgetPage.eq(index).addClass('active').css('z-index',1);
        $points.find('i').removeClass('active');
        $points.find('i').eq(index).addClass('active');
    }

    function start(){
        interval && clearInterval(interval);
        interval = setInterval(function(){
            if(cur>=count-1){
                cur=0;
            }else{
                cur++;
            }
            slider(cur);
        },2000);
    }

    function stop(){
        interval && clearInterval(interval);
        interval=0;
    }

    $widgetContainer.on("mouseover",function(){
        stop();
    }).on("mouseout",function(){
        start();
    });

    $points.find('i').on("mouseover",function(){
        stop();
        slider($(this).index());
    }).on("mouseout",function(){
        start();
    });

    slider(0);
    start();
};